package com.a.lib_base.base.ui

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.viewbinding.ViewBinding
import com.a.lib_base.base.viewmodel.BaseOwnerViewModel

/**
 * CREATE BY 黄炜强
 * 2022/7/27 14:13
 * Desc:
 * */
abstract class BaseMVIFragment<VB : ViewBinding>() : BaseViewModelFragment<VB>() {

    protected abstract fun onInitView()
    protected open fun onInitData() {}
    protected open fun onOutput() {}
    protected open fun onInput() {}

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        initViewModel()
    }

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        val onCreateView = super.onCreateView(inflater, container, savedInstanceState)
        onInitView()
        return onCreateView
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        onInitData()
        onOutput()
        onInput()
    }

    fun <T : BaseOwnerViewModel> getActivityOwnerViewModel(modelClass: Class<T>): T {
        val activityViewModel = super.getActivityViewModel(modelClass)
        activityViewModel.owner = this
        return activityViewModel
    }

    fun <T : BaseOwnerViewModel> getFragmentOwnerViewModel(modelClass: Class<T>): T {
        val fragmentViewModel = super.getFragmentViewModel(modelClass)
        fragmentViewModel.owner = this
        return fragmentViewModel
    }


}